package com.gk.chat.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.gk.chat.dto.FriendDTO;
import com.gk.chat.pojo.Contact;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ContactMapper extends BaseMapper<Contact> {

    /**
     * 获取好友列表
     * @param wrapper
     * @return
     */
    @Select("SELECT u.id AS userId, u.avatar AS avatar, u.nickname AS nickname,u.motto AS motto, c.remark AS remark,c.group_id AS groupId " +
            "FROM contact c INNER JOIN users u ON c.friend_id=u.id " +
            "${ew.customSqlSegment}")
    List<FriendDTO> selectFriends(@Param(Constants.WRAPPER) Wrapper<Contact> wrapper);

    @Select("SELECT count(friend_id) FROM contact c where user_id=#{id}")
    int selectFriendsCount(@Param("id") Long id);
}
